package client.vue;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import client.controller.choixJeuxController;
/**
 * 
 * @author David
 *
 */
public class ChoixJeuxVue extends JPanel{
	
	private static final long serialVersionUID = 1L;
	private JLabel titreLabel,nouvellePartieLabel, rejoindrePartieLabel;
	private JButton nouveauBouton,rejoindreBouton,rafrechirBouton;
	Fenetre fenetre;
	JComboBox partiEnCours;
	
	public ChoixJeuxVue(Fenetre f) {
    	this.fenetre = f;
		this.initialize();
		this.build();
	}
		
	public void initialize() {
		
        /* 1- Initialisation du container. */
        this.setLayout(new GridBagLayout());

        /* 2- Cr�ation et initialisation d'une s�rie de composants. */
        titreLabel = new JLabel("Blind test");
        nouvellePartieLabel = new JLabel("Cliquer ici : ");
        rejoindrePartieLabel = new JLabel("Partie en cours : ");
        
        nouveauBouton = new JButton("Nouvelle partie");
        rejoindreBouton = new JButton("Rejoindre");
        rafrechirBouton = new JButton("Rafrechir");
        
        partiEnCours = new JComboBox();
        
	}
	
	private void build() {
		  GridBagConstraints gbc = new GridBagConstraints();
		  
		  Font titreFont = new Font("Serif", Font.PLAIN, 26);
	      titreLabel.setFont(titreFont);
	      gbc.gridx = gbc.gridy = 0; 
	      gbc.gridwidth = GridBagConstraints.REMAINDER;
	      gbc.gridheight = 1;
	      gbc.anchor = GridBagConstraints.CENTER; 
	      gbc.insets = new Insets(15, 0, 15, 0); 
	      this.add(titreLabel, gbc);
     
	      //Nouvelle partie label
		  gbc.gridx = 0;
		  gbc.gridy ++;
		  gbc.gridheight = gbc.gridwidth = 1;
		  gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  this.add(nouvellePartieLabel, gbc);
		  
		  //nouvel partie bouton
		  gbc.gridx = 1;
		  gbc.fill = GridBagConstraints.HORIZONTAL;
		  gbc.gridwidth = GridBagConstraints.RELATIVE;
		  gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  nouveauBouton.addActionListener(new choixJeuxController(fenetre));
		  this.add(nouveauBouton, gbc);
	        
	      //rafrechir bouton 
		  gbc.gridx = 0;
		  gbc.gridy ++;
		  gbc.gridheight = gbc.gridwidth = 1;
		  gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  rafrechirBouton.addActionListener(new choixJeuxController(fenetre));
		  this.add(rafrechirBouton,gbc);
		  
		  //partie en cour liste
		  gbc.gridx = 1;
		  gbc.fill = GridBagConstraints.HORIZONTAL;
		  gbc.gridwidth = GridBagConstraints.RELATIVE;
		  gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  this.add(partiEnCours, gbc);
		  
	      //rejoindre partie label
		  gbc.gridx = 0;
		  gbc.gridy ++;
		  gbc.gridheight = gbc.gridwidth = 1;
		  gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  this.add(rejoindrePartieLabel, gbc);
		  
		  //rejoindre partie bouton
		  gbc.gridx = 1;
		  gbc.fill = GridBagConstraints.HORIZONTAL;
		  gbc.gridwidth = GridBagConstraints.RELATIVE;
		  gbc.anchor = GridBagConstraints.BASELINE_TRAILING;
		  gbc.insets = new Insets(10, 10, 0, 0);
		  rejoindreBouton.addActionListener(new choixJeuxController(fenetre));
		  this.add(rejoindreBouton, gbc);
	              
	      this.setMinimumSize(new Dimension(500, 325));
	}
	public String getPartiEnCours() {
		return partiEnCours.getSelectedItem().toString();
	}
	public JComboBox getListePartie(){
		return partiEnCours;
	}

	public void setPartiEnCours(String partiEnCours) {
		this.partiEnCours.addItem(partiEnCours);
	}
}